package com.ggh.jinjilive.dialog;

import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.ViewGroup;
import android.view.Window;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.amap.api.services.core.PoiItem;
import com.cy.dialog.BaseDialog;
import com.ggh.jinjilive.R;
import com.ggh.jinjilive.dialog.adapter.NearMessageAdapter;
import com.ggh.jinjilive.listener.AddItemOnClickListener;

import java.util.List;

public class NearMessageDialog extends BaseDialog {

    private NearMessageAdapter nearMessageAdapter;
    private RecyclerView rv;
    public NearMessageDialog(Context context) {
        super(context);
    }

    public NearMessageDialog(Context context, int themeResId) {
        super(context, themeResId);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        contentView(R.layout.dialog_near_message);
        animType(AnimInType.BOTTOM);
        gravity(Gravity.BOTTOM);

        rv = findViewById(R.id.rv);
        nearMessageAdapter = new NearMessageAdapter();
        nearMessageAdapter.setAddItemOnClickListener(new AddItemOnClickListener() {
            @Override
            public void onSkipClicked(int position, Object mObject) {
                if(null != addItemOnClickListener){
                    addItemOnClickListener.onSkipClicked(position,mObject);
                }
            }
        });
        rv.setLayoutManager(new LinearLayoutManager(getContext()));
        rv.setAdapter(nearMessageAdapter);
    }

    private AddItemOnClickListener addItemOnClickListener;
    public void setAddItemOnClickListener(AddItemOnClickListener addItemOnClickListener){
        this.addItemOnClickListener = addItemOnClickListener;
    }

    /**
     * 获取定位列表
     * @param poiItemList
     */
    public void setPoiItemList(List<PoiItem> poiItemList){
        nearMessageAdapter.setPoiItemList(poiItemList);
    }

    @Override
    public void show() {
        super.show();
        Window window = getWindow();
        //设置弹出位置
        window.setGravity(Gravity.BOTTOM);
        //设置对话框大小
        window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    }
}
